#include <stdio.h>
#include <string.h>

char* findLongestRepeatedSubstring(char* str) {
    int len = strlen(str);
    int maxLen = 0, maxStart = 0;
    for (int i = 0; i < len; i++) {
        for (int j = i + 1; j < len; j++) {
            int k = 0;
            while (str[i + k] == str[j + k] && i + k < len && j + k < len) {
                k++;
            }
            if (k > maxLen) {
                maxLen = k;
                maxStart = i;
            }
        }
    }
    char* result = (char*)malloc(maxLen + 1);
    strncpy(result, str + maxStart, maxLen);
    result[maxLen] = '\0';
    return result;
}
 
int main() {
    char str[] = "ababcabcd";
    char* result = findLongestRepeatedSubstring(str);
    printf("The longest repeated substring is: %s\n", result);
    free(result);
    return 0;
} 